load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda")
load("//bazel:tachyon.bzl", "if_c_shared_object")
load(
    "//bazel:tachyon_cc.bzl",
    "collect_hdrs",
    "tachyon_cc_library",
    "tachyon_cc_shared_library",
    "tachyon_cc_unittest",
)
load("//tachyon/build:version.bzl", "write_version_header")
load(
    ":version.bzl",
    "VERSION",
    "VERSION_MAJOR",
    "VERSION_MINOR",
    "VERSION_PATCH",
    "VERSION_PRERELEASE",
)

package(default_visibility = ["//visibility:public"])

write_version_header(
    name = "version_generated",
    lastchange = "//tachyon/build:lastchange",
    major = VERSION_MAJOR,
    minor = VERSION_MINOR,
    output = "version_generated.h",
    patch = VERSION_PATCH,
    prerelease = VERSION_PRERELEASE,
    project = "TACHYON_C",
)

tachyon_cc_library(
    name = "export",
    hdrs = ["export.h"],
)

tachyon_cc_library(
    name = "version",
    srcs = ["version.cc"],
    hdrs = [
        "version.h",
        ":version_generated",
    ],
    deps = [":export"],
)

tachyon_cc_shared_library(
    name = "tachyon",
    linkstatic = True,
    soversion = VERSION,
    tags = ["manual"],
    deps = if_c_shared_object([
        ":version",
        "//tachyon/c/base",
        "//tachyon/c/crypto",
        "//tachyon/c/math",
        "//tachyon/c/zk",
    ]) + if_cuda([
        "@local_config_cuda//cuda:cudart_static",
    ]),
)

collect_hdrs(
    name = "tachyon_hdrs",
    hdrs = [
        "api.h",
        "export.h",
        "version.h",
        ":version_generated",
    ],
    deps = [
        "//tachyon/c/base:base_hdrs",
        "//tachyon/c/crypto:crypto_hdrs",
        "//tachyon/c/math:math_hdrs",
        "//tachyon/c/zk:zk_hdrs",
    ],
)

tachyon_cc_unittest(
    name = "c_unittests",
    srcs = [
        "version_unittest.cc",
    ],
    deps = [
        ":version",
        "@com_google_absl//absl/strings",
    ],
)
